package net.seehope.foodie.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import net.seehope.foodie.properties.ProjectProperties;

//cors放行配置
@Configuration
public class CorsConfig {
	
	
	@Autowired
	private ProjectProperties properties;
	
	@Bean
	public CorsFilter corsFilter() {
		CorsConfiguration corsConfiguration = new CorsConfiguration();
		corsConfiguration.addAllowedOrigin(properties.getBrowser().getBaseStaticServerUrl());
		corsConfiguration.setAllowCredentials(true);
		corsConfiguration.addAllowedMethod("*");
		corsConfiguration.addAllowedHeader("*");
		
		UrlBasedCorsConfigurationSource corsSource = new UrlBasedCorsConfigurationSource();
	    corsSource.registerCorsConfiguration("/**", corsConfiguration);
	    return new CorsFilter(corsSource);
		
		
	}
	
}
